# Contributor: Leonardo Arena <rnalrd@alpinelinux.org>
# Contributor: Jakub Jirutka <jakub@jirutka.cz>
# Maintainer: Jakub Jirutka <jakub@jirutka.cz>
#
# TODO: Fix init script (remove bashisms)
pkgname=ocfs2-tools
pkgver=1.8.6
pkgrel=0
pkgdesc="Oracle Cluster File System 2 Core Tools"
url="https://oss.oracle.com/projects/ocfs2-tools"
arch="all"
license="GPL-2.0-only"
depends_dev="$pkgname=$pkgver-r$pkgrel glib-dev"
makedepends="$depends_dev autoconf automake e2fsprogs-dev libaio-dev libtool
	libtirpc-dev linux-headers ncurses-dev readline-dev"
subpackages="$pkgname-dev $pkgname-doc"
source="ocfs2-tools-$pkgver.tar.gz::https://github.com/markfasheh/ocfs2-tools/archive/ocfs2-tools-$pkgver.tar.gz
	o2cb.initd
	o2cb.confd
	cluster.conf
	musl-libocfs2-__bswap_constant_32.patch
	musl-o2info-atimensec.patch
	musl-sys-raw.h.patch
	fix-operations-include-ioctl.patch
	fix-o2monitor-undeclared-PATH_MAX.patch
	tunefs-remove-op_query.patch
	fix-sysmacros.patch
	"
builddir="$srcdir/$pkgname-$pkgname-$pkgver"

prepare() {
	update_config_guess
	update_config_sub
	default_prepare

	./autogen.sh
}

build() {
	# _GNU_SOURCE is needed for loff_t from fcntl.h; it's already defined
	# in many ocfs2-tools' sources, but after fcntl.h is included.
	export CFLAGS="$CFLAGS -D_GNU_SOURCE $(pkgconf --cflags libtirpc)"
	export LDFLAGS="$LDFLAGS $(pkgconf --cflags libtirpc)"

	./configure \
		--build=$CBUILD \
		--host=$CHOST \
		--prefix=/usr \
		--sysconfdir=/etc \
		--mandir=/usr/share/man \
		--disable-glibtest \
		--disable-static
	make -j1
}

package() {
	make DESTDIR="$pkgdir" install
	rm -f  "$pkgdir"/usr/lib/*.a

	# FIXME: remove bashisms
	#install -m 755 -D "$srcdir"/o2cb.initd "$pkgdir"/etc/init.d/o2cb
	#install -m 644 -D "$srcdir"/o2cb.confd "$pkgdir"/etc/conf.d/o2cb
	install -m 644 -D "$srcdir"/cluster.conf "$pkgdir"/etc/ocfs2/cluster.conf
}

sha512sums="71abe46152b065b9ba7db192b9f14ed28a1fbf0fa68822d4e8188c6f1654dfaaa29ae72ea4219bd68e7fade7791a08d36cbd5af5a16a2ee96e194ecb6f0d950b  ocfs2-tools-1.8.6.tar.gz
e6fd44358ba5a38446a8bea60c493f4ef9b7a2d7c0076116e91f0edabb66da1fd90be884a46052592f69e338887d4df5c7b7c0b01fadf837fdbc7906a96de52a  o2cb.initd
e510f08a9adc2d7c07e7b8a4d2c503c5a130a156ab1bf1cf45d8480dd94490968f718e966d0bae090a883ff36768e17971415f9905bd5dcf8632f16f7c0b931e  o2cb.confd
f844e5389e0b42d6f91a1335bd2ef4d2666e5b883c999d05acd3bc63ad901bc5838aa4da35bb1d069463d7cc7dcfa277dbaa938b5953e8d420a37cfbb30f24f3  cluster.conf
87ea579ddb4a6ae34c5b815fe9015dc0168cb267312f9ef3dccfd16cd65a1f13ef1275dda72308d952ca844e42a486c891340210c4757866f2caacd0d6d3a916  musl-libocfs2-__bswap_constant_32.patch
d1eb24086f71f22e0333f4c246389ce82c9b4540bb0a2d091f6deee7f563c7e5457a838937cd07f1b90359e9c215639aebcbc54c551fb0e9e3617f29c03d49a1  musl-o2info-atimensec.patch
b471c21f30f7ebba05ed8e4c63ff00b4ddad7e6095d256929472d61368dcb7566296201ad0af382a21f0a16c47f23cfa256ad91e6629f17595034e4807c96f3b  musl-sys-raw.h.patch
41b5e0d2eae738a8e05b6377e6dd4fc79592c6fc7b62dbc1ea6d7bd1fdb80122bc2f915748e64e30c9e964a1ebc73a65d81b5409fd499a959b3015d8c0683ead  fix-operations-include-ioctl.patch
35d5872e6a3651583442b3a333a2e866bf241b4fc19bdbabf4bb46cdbdb6b2806d81092b1fa80a9841a49e95a40d2bc09d12ad33e8cfbf3c267698eb9120b307  fix-o2monitor-undeclared-PATH_MAX.patch
c614235c98426a60d484203b47c44643833496de9864f2f6b1bedec206de33231878799d0b16ad2462c7ed2920cd0d8f9fd41fd7b1fff5b644e8be4b31ed815d  tunefs-remove-op_query.patch
a4b202ea3518f766e1b43b0acb1acc961d5c4d9d6792eaa77d64a07f97050be090e0233509b34fe9553328ec0e85c4735984a7009f6dc8b8325350e3525158d7  fix-sysmacros.patch"
